macro(x_remove_all_files_of_charts)
  # If Qt Charts is not found, we need to remove the files that depend on it
  file(GLOB_RECURSE CHARTS_FILES "${CMAKE_SOURCE_DIR}/src/page/panels/outputpanels/charts/*.*")
  message(STATUS "[Charts]Remove Qt Charts files from X_SOURCES")
  foreach(file ${CHARTS_FILES})
    message(STATUS "[Charts]Remove file: ${file}")
    list(REMOVE_ITEM X_SOURCES "${file}")
  endforeach()
endmacro()

if(QT_VERSION VERSION_LESS 6.9.0)
  message(STATUS "[xTools-charts] Using Qt Charts module.")
  find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS Charts)
  if(Qt${QT_VERSION_MAJOR}Charts_FOUND)
    add_compile_definitions(X_ENABLE_CHARTS)
    list(APPEND X_LIBS Qt${QT_VERSION_MAJOR}::Charts)
  else()
    x_remove_all_files_of_charts()
  endif()
else()
  # TODO: Using QGraphs module to replace Qt Charts
  message(STATUS "[xTools-charts] Using Qt Charts module.")
  find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS Charts)
  if(Qt${QT_VERSION_MAJOR}Charts_FOUND)
    add_compile_definitions(X_ENABLE_CHARTS)
    list(APPEND X_LIBS Qt${QT_VERSION_MAJOR}::Charts)
  else()
    x_remove_all_files_of_charts()
  endif()
endif()
